package com.omg.persistence.dao.lifepoint.sqlmapdao;

import java.util.List;

import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.template.SqlMapDaoTemplate;
import com.omg.persistence.dao.lifepoint.entity.LPComment;
import com.omg.persistence.dao.lifepoint.iface.LPCommentDao;

/**
 * 
 * @author xiazhiquan
 * 
 *         May 28, 2011
 */
public class LPCommentSqlMapDao extends SqlMapDaoTemplate implements
		LPCommentDao {

	public LPCommentSqlMapDao(DaoManager daoManager) {
		super(daoManager);
	}

	@Override
	public List<LPComment> getCommentsByActivityId(String activityid) {
		return this.queryForList("getCommentsByActivityId", activityid);
	}

	@Override
	public LPComment getCommentByCommentId(String commentid) {
		return (LPComment) this.queryForObject("getCommentByCommentId",
				commentid);
	}

	@Override
	public int addComment(LPComment comment) {
		try {
			this.insert("addComment", comment);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	@Override
	public int updateComment(LPComment comment) {
		try {
			this.update("updateComment", comment);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	@Override
	public int deleteComment(String commentid) {
		try {
			this.delete("deleteComment", commentid);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	@Override
	public int getCommentTotalByActivityId(String activityid) {
		Object obj = this.queryForObject("getCommentTotalByActivityId",
				activityid);
		if (obj == null) {
			return 0;
		}
		return (Integer) obj;
	}

}
